package com.cyt.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cyt.dao.impl.GongShiDaoImpl;
import com.cyt.dao.impl.LunBoTuDaoImpl;
import com.cyt.dao.impl.SPFeiLeiDaoImpl;
import com.cyt.dao.impl.ShangPingXXTwoDaoImpl;
import com.cyt.entity.GongShi;
import com.cyt.entity.LunBoTu;
import com.cyt.entity.SPFeiLei;
import com.cyt.entity.ShangPingXX;
import com.cyt.util.BaseServlet;
import com.cyt.util.Result;
import com.google.gson.Gson;


public class AdminGongShiServlet extends BaseServlet {
	
	
	/**
	 * 查询公司表的所有信息
	 * localhost:8080/shiping/adminGongShi?reqName=getGongShi
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void getGongShi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	     
		 response.setCharacterEncoding("UTF-8");//设置响应编码格式
	     PrintWriter out=response.getWriter();//创建out对象
		GongShiDaoImpl gongShiDaoi=new GongShiDaoImpl();//创建公司的实现类对象
	     GongShi gsLists= gongShiDaoi.getGongShi();//查到的所有公司信息
	
	     Gson gson=new Gson();
	     String res =gson.toJson(gsLists);//将spLists里面的数据转换为json字符串
	     
	     out.print(res);//响应数据
	     
	     out.flush();
	     out.close();
	}
	
	
	/**
	 * localhost:8080/shiping/adminGongShi?reqName=xiuGaiGongShi
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void xiuGaiGongShi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
	    PrintWriter out=response.getWriter();
	    GongShiDaoImpl gsDaoi=new GongShiDaoImpl();
	    
	    
		String logo=request.getParameter("logo");
		String name=request.getParameter("name");
		String wangzhi=request.getParameter("wangzhi");
		String jieshao=request.getParameter("jieshao");
		String dianhua=request.getParameter("dianhua");
		String youxiang=request.getParameter("youxiang");
		String dizhi=request.getParameter("dizhi");
		String xiangxi=request.getParameter("xiangxi");
		String wenhua=request.getParameter("wenhua");
		
		GongShi gs= new GongShi(logo, name, wangzhi, jieshao, dianhua, youxiang, dizhi, xiangxi, wenhua);
		int n =gsDaoi.xiuGaiGongShi(gs);
	    
	    if (n>0) {//删除成功
			out.print(Result.toClient(true, "修改成功", ""));
		} else {//删除失败
			out.print(Result.toClient(false, "修改失败", ""));

		}
	    out.flush();
	    out.close();
	}
	
}
